package com.totofgeek.contactsboard.outils.utilitaires;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.totofgeek.contactsboard.constantes.IConstantesCommunes;

public class DateUtilitaire implements IConstantesCommunes
{

	/**
	 * Comparaison de 2 dates sans les heures
	 * 
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static boolean comparerDateSansHeure(Date date1, Date date2)
	{
		if (date1 == null && date2 == null)
		{
			return true;
		}
		if (date1 != null && date2 != null)
		{
			GregorianCalendar gregorianCalendar1 = new GregorianCalendar();
			GregorianCalendar gregorianCalendar2 = new GregorianCalendar();
			gregorianCalendar1.setTime(date1);
			gregorianCalendar2.setTime(date2);
			gregorianCalendar1.set(Calendar.HOUR_OF_DAY, 0);
			gregorianCalendar1.set(Calendar.MINUTE, 0);
			gregorianCalendar1.set(Calendar.SECOND, 0);
			gregorianCalendar1.set(Calendar.MILLISECOND, 0);
			gregorianCalendar2.set(Calendar.HOUR_OF_DAY, 0);
			gregorianCalendar2.set(Calendar.MINUTE, 0);
			gregorianCalendar2.set(Calendar.SECOND, 0);
			gregorianCalendar2.set(Calendar.MILLISECOND, 0);
			return (gregorianCalendar1.equals(gregorianCalendar2));
		}
		return false;
	}

	/**
	 * @param dateString
	 * @return
	 * @throws ParseException
	 */
	public static Date StringYYYYMMDDToDate(String dateString) throws ParseException
	{
		SimpleDateFormat sp = new SimpleDateFormat(IConstantesTechniques.FORMAT_DATE);
		return sp.parse(dateString);
	}

	/**
	 * @param date
	 * @return
	 */
	public static String DateToStringYYYYMMDD(Date date)
	{
		SimpleDateFormat sp = new SimpleDateFormat(IConstantesTechniques.FORMAT_DATE);
		return sp.format(date);
	}
}
